#include<bits/stdc++.h>
using namespace std;
struct stu
{
	string name;
	int y,m,d;
}s[100];
bool cmp(stu a, stu b)
{
	if(a.y!=b.y)
	return a.y>b.y;
	else if(a.m!=b.m)
	return a.m>b.m;
	else 
	return a.d>b.d;
}
int main()
{
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>s[i].name>>s[i].y>>s[i].m>>s[i].d;
	sort(s+1,s+i,cmp);
	for(i=1;i<=n;i++)
	cout<<s[i].name<<" "<<s[i].y<<" "<<s[i].m<<" "<<s[i].d<<endl;
    return 0;
}
